<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 *
 * Smarty {news_category} function plugin
 * @param array|null $params
 * @param Smarty $smarty
 */
function smarty_function_news_category($params,$smarty){
	if (!isset($params['category_id'])){
		return "";
	}
	$smarty->CI->load->model('news/news_model');
	$categories = array();
	$games= array();
	$categories = $smarty->CI->news_model->get_categories(array('category_id'=>$params['category_id']), false, false);

	$html ="";
	$limit = 4;
	if (isset($params['limit'])){
		$limit = $params['limit'];
	}
	foreach ($categories as $category){
		$html .= "<div class=\"featured-game\">\n";
		$html .="<div class=\"featured-title\">\n".
			"<h3><span>{$category['name']}</span><a href=\"{$category['link']}\" title=\"{$category['name']}\">Xem thêm</a></h3>\n".
			"</div>\n";
		$games = $smarty->CI->news_model->get_news(array('category_id'=>$category['category_id'],'limit'=>$limit));
		$html .="<div class=\"featured-content\">"."\n";
		$html .="<ul class=\"glist\">"."\n";
		if (is_array($games) && count($games) > 0){
			foreach ($games as $game){
				$html .="<li class=\"gitem\">"
					."<div class=\"gimg\"><a href=\"{$game['link']}\" title=\"{$game['name']}\"><img src=\"{$game['image']}\" alt=\"{$game['name']}\" /></a></div>"
					."<h2><a href=\"{$game['link']}\" title=\"{$game['link']}\">{$game['name']}</a>";
					if ($game['is_hot'] == 1){
						$html .= " <img alt=\"Hot\" src=\"images/icon/hot.gif\" />";
					}
				$html .="</h2>";
//				$html .="<div class=\"ginfo\">".substr_utf8(strip_tags($game['description']),0,100)."</div>"
//					."</li>"."\n";
			}
		}
		$html .="</ul>"."\n";
		$html .="</div>"."\n";
		$html .= "</div>\n";
	}
	
	
	return $html;
}